package cn.edu.scau.cmi.wujiaming.experiment1;

import java.util.HashSet;
import java.util.Set;

public class MarShell {
	private static Set<MarShell> marShellSet = new HashSet<>();

	private String name;

	private MarShell(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public static MarShell getInstance(String name) {
		// Iterator it = marShellSet.iterator();
		/*
		 * if(marShellSet.size() == 0){ MarShell mar = new MarShell(name);
		 * marShellSet.add(mar); return mar; }
		 */
		for (MarShell mar : marShellSet) {
			if (mar.getName().equals(name)) {
				return mar;
			}
		}
		if (marShellSet.size() < 10) {
			MarShell mar = new MarShell(name);
			marShellSet.add(mar);
			return mar;
		} else {
			// System.out.println("There can only have 10 marshells!");
			return null;
		}
	}
}